package site.teamo.biu.net.server.controller;

import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import site.teamo.biu.net.common.http_https_proxy.ConnectionState;
import site.teamo.biu.net.server.core.http_https_proxy.HttpHttpsProxyService;
import site.teamo.biu.net.server.core.http_https_proxy.state.HttpHttpsProxyState;
import site.teamo.biu.tool.core.model.BiuJSONResult;
import site.teamo.biu.tool.core.util.BiuJSONResultUtils;

/**
 * @author haocongshun
 * @date 2023/03/07 15:02:31
 */
@RestController
@RequestMapping("/http-https-proxy")
public class HttpHttpsProxyController {

    @Resource
    private HttpHttpsProxyService httpHttpsProxyService;

    @Operation(summary = "修改端口")
    @PostMapping("/chang-port")
    public BiuJSONResult<Boolean> changePort(@RequestParam Integer port) {
        httpHttpsProxyService.changePort(port);
        return BiuJSONResultUtils.ok(true);
    }

    @Operation(summary = "查询状态")
    @GetMapping("/query-state")
    public BiuJSONResult<HttpHttpsProxyState> queryState() {
        return BiuJSONResultUtils.ok(httpHttpsProxyService.state());
    }

    @Operation(summary = "查询代理连接的状态")
    @GetMapping("/query-proxy-connection-state")
    public BiuJSONResult<ConnectionState> queryProxyConnectionState() {
        return BiuJSONResultUtils.ok(httpHttpsProxyService.proxyConnectionState());
    }
}
